package cn.zd.demo1.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import cn.zd.demo1.data.Fruits;
import cn.zd.demo1.fragment.MyDynamicFragment;

public class MyFragmentAdapter extends FragmentPagerAdapter {
    public MyFragmentAdapter(@NonNull FragmentManager fm) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        Fruits fruits = Fruits.initData.get(position);
        return MyDynamicFragment.newInstance(position,fruits.getImg(),fruits.getName(),fruits.getDetail());
    }

    @Override
    public int getCount() {
        return Fruits.initData.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return Fruits.initData.get(position).getName();
    }
}
